package com.xu.ThrreadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 创建一个固定大小的线程池
 *
 * 结论：execute 只能执行不带返回值的任务
 *
 */
public class ThreadPoolDemo1 {
    public static void main(String[] args) {
        //1.创建一个包含5个线程的线程池
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        //2.使用线程池执行任务
        for (int i = 0; i <10; i++) {
            //给线程池添加任务
            executorService.execute(()->{
                System.out.println("线程名称："+Thread.currentThread().getName());
            });
        }
    }
}
